home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16.lha / Python-1.6 / Lib / Python1.6 / distutils / extension.py < prev    next >
Encoding:
Python Source  |  2000-08-13  |  4.8 KB  |  110 lines

  1. """distutils.extension
  2.  
  3. Provides the Extension class, used to describe C/C++ extension
  4. modules in setup scripts."""
  5.  
  6. # created 2000/05/30, Greg Ward
  7.  
  8. __revision__ = "$Id: extension.py,v 1.5 2000/08/13 00:41:40 gward Exp $"
  9.  
  10. from types import *
  11.  
  12.  
  13. # This class is really only used by the "build_ext" command, so it might
  14. # make sense to put it in distutils.command.build_ext.  However, that
  15. # module is already big enough, and I want to make this class a bit more
  16. # complex to simplify some common cases ("foo" module in "foo.c") and do
  17. # better error-checking ("foo.c" actually exists).
  18. # Also, putting this in build_ext.py means every setup script would have to
  19. # import that large-ish module (indirectly, through distutils.core) in
  20. # order to do anything.
  21.  
  22. class Extension:
  23.     """Just a collection of attributes that describes an extension
  24.     module and everything needed to build it (hopefully in a portable
  25.     way, but there are hooks that let you be as unportable as you need).
  26.  
  27.     Instance attributes:
  28.       name : string
  29.         the full name of the extension, including any packages -- ie.
  30.         *not* a filename or pathname, but Python dotted name
  31.       sources : [string]
  32.         list of source filenames, relative to the distribution root
  33.         (where the setup script lives), in Unix form (slash-separated)
  34.         for portability.  Source files may be C, C++, SWIG (.i),
  35.         platform-specific resource files, or whatever else is recognized
  36.         by the "build_ext" command as source for a Python extension.
  37.       include_dirs : [string]
  38.         list of directories to search for C/C++ header files (in Unix
  39.         form for portability)
  40.       define_macros : [(name : string, value : string|None)]
  41.         list of macros to define; each macro is defined using a 2-tuple,
  42.         where 'value' is either the string to define it to or None to
  43.         define it without a particular value (equivalent of "#define
  44.         FOO" in source or -DFOO on Unix C compiler command line)
  45.       undef_macros : [string]
  46.         list of macros to undefine explicitly
  47.       library_dirs : [string]
  48.         list of directories to search for C/C++ libraries at link time
  49.       libraries : [string]
  50.         list of library names (not filenames or paths) to link against
  51.       runtime_library_dirs : [string]
  52.         list of directories to search for C/C++ libraries at run time
  53.         (for shared extensions, this is when the extension is loaded)
  54.       extra_objects : [string]
  55.         list of extra files to link with (eg. object files not implied
  56.         by 'sources', static library that must be explicitly specified,
  57.         binary resource files, etc.)
  58.       extra_compile_args : [string]
  59.         any extra platform- and compiler-specific information to use
  60.         when compiling the source files in 'sources'.  For platforms and
  61.         compilers where "command line" makes sense, this is typically a
  62.         list of command-line arguments, but for other platforms it could
  63.         be anything.
  64.       extra_link_args : [string]
  65.         any extra platform- and compiler-specific information to use
  66.         when linking object files together to create the extension (or
  67.         to create a new static Python interpreter).  Similar
  68.         interpretation as for 'extra_compile_args'.
  69.       export_symbols : [string]
  70.         list of symbols to be exported from a shared extension.  Not
  71.         used on all platforms, and not generally necessary for Python
  72.         extensions, which typically export exactly one symbol: "init" +
  73.         extension_name.
  74.     """
  75.  
  76.     def __init__ (self, name, sources,
  77.                   include_dirs=None,
  78.                   define_macros=None,
  79.                   undef_macros=None,
  80.                   library_dirs=None,
  81.                   libraries=None,
  82.                   runtime_library_dirs=None,
  83.                   extra_objects=None,
  84.                   extra_compile_args=None,
  85.                   extra_link_args=None,
  86.                   export_symbols=None,
  87.                  ):
  88.  
  89.         assert type(name) is StringType, "'name' must be a string"
  90.         assert (type(sources) is ListType and
  91.                 len(sources) >= 1 and
  92.                 map(type, sources) == [StringType]*len(sources)), \
  93.                 "'sources' must be a non-empty list of strings"
  94.  
  95.         self.name = name
  96.         self.sources = sources
  97.         self.include_dirs = include_dirs or []
  98.         self.define_macros = define_macros or []
  99.         self.undef_macros = undef_macros or []
  100.         self.library_dirs = library_dirs or []
  101.         self.libraries = libraries or []
  102.         self.runtime_library_dirs = runtime_library_dirs or []
  103.         self.extra_objects = extra_objects or []
  104.         self.extra_compile_args = extra_compile_args or []
  105.         self.extra_link_args = extra_link_args or []
  106.         self.export_symbols = export_symbols or []
  107.  
  108. # class Extension
  109.